package com.un.ebs.sys.service.impl;

import com.un.ebs.core.UserContext;
import com.un.ebs.core.UserContextService;
import com.un.ebs.core.metadata.ResourceData;
import com.un.ebs.sys.service.DictionaryValueService;
import com.un.ebs.sys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *
 * </p>
 *
 * @author liubo
 * @create 2021-05-27 16:59
 */
@Service
public class UserContextServiceImpl implements UserContextService {

    @Autowired
    private UserService userService;

    @Autowired
    private DictionaryValueService dictionaryValueService;

    @Override
    public String createToken(UserContext user) {
        return userService.createToken(user);
    }

    @Override
    public UserContext getUserContext() {
        return userService.getUserContext();
    }

    @Override
    public UserContext getUserContext(String userId, String tenantId) {
        return userService.getUserContext(userId, tenantId);
    }

    @Override
    public UserContext getUserContext(String token) {
        return userService.getUserContext(token);
    }

    @Override
    public List<ResourceData> queryDictionKey(String dictCode) {
        return dictionaryValueService.queryValueByKey(dictCode).stream().map(s -> {
            return new ResourceData(s.getValue(), s.getValue(), s.getDescription());
        })
                .collect(Collectors.toList());
    }
}
